#include "../include/ExplicitAddressingPacket.hpp"
#include "../include/util.hpp"

const uint64_t broadcast_64 = 0x000000000000FFFF;
const uint16_t broadcast_16 = 0xFFFE;

enum broadcast_radius {
    max_hops = 0x0
};

ExplicitAddressingPacket::ExplicitAddressingPacket() :
    source_endpoint(0xE8),
    dest_endpoint(0xE8),
    cluster_id(0x12),
    profile_id(0xC105),
    broadcast_radius(0)
{}
ExplicitAddressingPacket::~ExplicitAddressingPacket(){}

void ExplicitAddressingPacket::assemble_payload(uint8_t     frame_id,
                                                uint32_t    lower_addr,
                                                std::string data) {

    payload.clear();
    payload.push_back(explicit_addressing_ft);
    payload.push_back(frame_id);

    push_back_32(&payload, upper_addr);
    push_back_32(&payload, lower_addr);
    push_back_16(&payload, broadcast_16);

    payload.push_back(source_endpoint);
    payload.push_back(dest_endpoint);

    push_back_16(&payload, cluster_id);
    push_back_16(&payload, profile_id);

    payload.push_back(max_hops);
    payload.push_back(options);

    for (int i = 0; data[i] != '\0'; ++i) {
        payload.push_back(data[i]);
    }
}


std::vector<uint8_t> * ExplicitAddressingPacket::get_payload() {
    return (&payload);
}
